<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'homeUrl' => Yii::getAlias('@backendUrl'),
    'controllerNamespace' => 'backend\controllers',
    'bootstrap' => ['log'],
    'defaultRoute' => 'site/dashboard',
    'controllerMap' => [
        'file-manager-elfinder' => [
            'class' => 'mihaildev\elfinder\Controller',
            'access' => [
                'manager'
            ],
            'disabledCommands' => [
                'netmount'
            ],
            'roots' => [
                [
                    'baseUrl' => '@storageUrl',
                    'basePath' => '@storage/web',
                    'path' => '/uploads',
                    'access' => [
                        'read' => 'manager',
                        'write' => 'manager'
                    ]
                ]
            ]
        ],
        'ueditor' => [
            'class' => 'common\ueditor\UEditorController',
            'rootUrl' => '@storageUrl/uploads',
            'rootPath' => '@storage/web/uploads',
            'thumbnail' => false,//如果将'thumbnail'设置为空，将不生成缩略图。
            'watermark' => [    //默认不生存水印
                'path' => '', //水印图片路径
                'start' => [0, 0] //水印图片位置
            ],
            'zoom' => ['height' => 500, 'width' => 500], //缩放，默认不缩放
            'config' => [
                //server config @see http://fex-team.github.io/ueditor/#server-config
                'imagePathFormat' => '/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'scrawlPathFormat' => '/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'snapscreenPathFormat' => '/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'catcherPathFormat' => '/image/{yyyy}{mm}{dd}/{time}{rand:6}',
                'videoPathFormat' => '/video/{yyyy}{mm}{dd}/{time}{rand:6}',
                'filePathFormat' => '/file/{yyyy}{mm}{dd}/{rand:4}_{filename}',
                'imageManagerListPath' => '/image/',
                'fileManagerListPath' => '/file/',
            ]
        ]
    ],
    'components' => [
        'assetManager' => [
            'class' => 'yii\web\AssetManager',
            'linkAssets' => true,
            'appendTimestamp' => YII_ENV_DEV
        ],
        'view' => [
            'class' => 'yii\web\View',
            'renderers' => [
                'html' => [
                    'class' => 'yii\smarty\ViewRenderer'
                ]
            ]
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error'
        ],
        'user' => [
            'class' => 'yii\web\User',
            'identityClass' => 'common\modules\user\models\AdminIdentify',
            'loginUrl' => [
                'user/sign-in/login'
            ],
            'idParam'           => '_aId',
            'identityCookie'    => ['name'=>'_aIdentity','httpOnly' => true],
            'enableAutoLogin' => true,
            'as afterLogin' => 'common\behaviors\LoginTimestampBehavior'
        ],
        'urlManager' => require (__DIR__ . '/_urlManager.php'),
        'frontendCache' => require (Yii::getAlias('@frontend/config/_cache.php'))
    ],
    'modules' => [
        'modularity' => [
            'class' => 'common\modules\modularity\backend\Module'
        ]
    ],
    'as globalAccess' => [
        'class' => '\common\behaviors\GlobalAccessBehavior',
        'rules' => [
            [
                'controllers' => [
                    'user/sign-in'
                ],
                'allow' => true,
                'roles' => [
                    '?'
                ],
                'actions' => [
                    'login'
                ]
            ],
            [
                'controllers' => [
                    'user/sign-in'
                ],
                'allow' => true,
                'roles' => [
                    '@'
                ],
                'actions' => [
                    'logout'
                ]
            ],
            [
                'controllers' => [
                    'site'
                ],
                'allow' => true,
                'roles' => [
                    '?',
                    '@'
                ],
                'actions' => [
                    'error'
                ]
            ],
            [
                'controllers' => [
                    'debug/default'
                ],
                'allow' => true,
                'roles' => [
                    '?'
                ]
            ],
            [
                'controllers' => [
                    'user/user'
                ],
                'allow' => true,
                'roles' => [
                    'administrator'
                ]
            ],
            [
                'controllers' => [
                    'user/user'
                ],
                'allow' => false
            ],
            [
                'allow' => true,
                'roles' => [
                    'manager'
                ]
            ]
        ]
    ],
    'as locale' => [
        'class' => 'common\behaviors\LocaleBehavior',
        'enablePreferredLanguage' => true
    ],
    'params' => $params,
];
